﻿using mozhi.smarterp.Finance.Logs.Repository;
using mozhi.smarterp.Finance.Querys;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.Finance.Logs
{
    public class OperationLogAppService : FinanceAppService, IOperationLogAppService
    {
        private IOperationLogRepository _operationLogRepository;

        public OperationLogAppService(IOperationLogRepository operationLogRepository) 
        {
            _operationLogRepository = operationLogRepository;
        }

        public async Task<PagedResultDto<OperationLogDto>> FindAsync(OperationLogPageQuery query)
        {
            var logs = await _operationLogRepository.FindAsync(query);

            var total = await _operationLogRepository.GetCountAsync(query);

            var result = new PagedResultDto<OperationLogDto>();

            result.TotalCount = total;
            result.Items = ObjectMapper.Map<List<OperationLog>, List<OperationLogDto>>(logs);

            return result;
        }
    }
}
